package com.kotlin.myapplicationd.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.kotlin.myapplicationd.R;
import com.kotlin.myapplicationd.base.BaseActivity;
import com.kotlin.myapplicationd.tools.ToolAlert;
import com.kotlin.network.bean.LoginBean;
import com.kotlin.network.model.INormalData;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by dong.xu on 2017/6/1.
 */

public class LoginActivity extends BaseActivity {
    @BindView(R.id.edt_cash_year)
    EditText edtCashYear;
    @BindView(R.id.edt_rate)
    EditText edtRate;
    @BindView(R.id.edt_year)
    EditText edtYear;
    @BindView(R.id.tv_sum)
    TextView tvSum;
    @BindView(R.id.btn_sum)
    Button btnSum;

    @Override
    public int bindLayout() {
        return R.layout.activity_login;
    }


    private void login(String strUsername, String strPassword) {

        getGlobalCommonPresenter().login(strUsername, strPassword, new INormalData<LoginBean>() {
            @Override
            public void load(LoginBean data) {

            }

            @Override
            public void error(String errmsg, int code) {


            }
        }, true);


    }


    @Override
    public void initParams(Bundle params) {

    }

    @Override
    public void initView(View view) {
        ButterKnife.bind(this);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void doBusiness(Context mContext) {
        //login("18550009543","123456");
        //sum(33, 0.05, 15);
    }

    @Override
    public void resume() {

    }

    @Override
    public void destroy() {

    }

    /**
     * DCF估值
     *
     * @param C    第i年现金流 单位 亿元
     * @param r    贴现率
     * @param year 年限
     */
    private void sum(int C, double r, int year) {
        double sum = 0;
        for (int i = 1; i <= year; i++) {
            //Math.pow(1.05,i);
            sum = sum + C / Math.pow(1 + r, i);
        }

        //ToolAlert.toastLong(String.valueOf(sum));
        tvSum.setText("估值："+String.valueOf(sum)+"亿");
    }




    @OnClick(R.id.btn_sum)
    public void onViewClicked() {
        int c = Integer.valueOf(edtCashYear.getText().toString());
        double r = Double.valueOf(edtRate.getText().toString());
        int year = Integer.valueOf(edtYear.getText().toString());
        sum(c, r, year);

    }
}
